package com.ronz.recursion;

/**
 * @Description 递归的基本演示
 * @Author Ronz
 * @Date 2021/1/2 18:50
 * @Version 1.0
 */
public class No1_Recursion_BasicDemo {


    public static void main(String[] args) {
        // 递归打印
        // printHello(3);

        // 计算阶乘
        int factorial = getFactorial(4);
        System.out.println(factorial);
    }

    /**
     * @Description 递归打印 Hello world
     * @Param [n]
     * @return void
     */
    public static void printHello(int n){
        if (n > 1){
            printHello(n-1);
        }
        System.out.println("Hello World!");
    }

    /**
     * @Description 计算 n 的阶乘
     * @Param
     * @return
     */
    public static int getFactorial(int n){
        if (n == 1){
            return 1;
        }else{
            return n * getFactorial(n-1);
        }
    }
}
